import requests
import time
from bs4 import BeautifulSoup


def get_python_versions():
	url = 'https://www.python.org/downloads/'
	res = requests.get(url)
	soup = BeautifulSoup(res.text, 'html.parser')
	version_list = soup.select('.list-row-container')
	for item in version_list[1].select('li'):
		span = item.select('span')
		s0 = span[0].select('a')[0].text
		s1 = span[1].text
		if 'Sept.' in s1:
			s1 = s1.replace('Sept.', 'Sep.')
		if '.' in s1:
			s1_format = time.strftime('%Y-%m-%d', time.strptime(s1, '%b. %d, %Y'))
		else:
			s1_format = time.strftime('%Y-%m-%d', time.strptime(s1, '%B %d, %Y'))
		print(s0, s1_format)




def get_spark_versions():
	url = 'https://spark.apache.org/news/'
	res = requests.get(url)
	soup = BeautifulSoup(res.text, 'html.parser')
	# print(res.text)
	version_list = soup.select('.hentry')
	for item in version_list:
		header = item.select('header')[0]
		version = header.select('h3')[0].text
		release_date = header.select('div')[0].text
		if 'released' in version:
			version = version.replace(' released', '')
			release_date = time.strftime('%Y-%m-%d', time.strptime(release_date, '%B %d, %Y'))
			print(version, release_date)

if __name__ == '__main__':
	get_spark_versions()grab